package com.zimin.common.exception;

import com.zimin.common.utils.ObjectUtils;
import com.zimin.shared.enums.ResponseStatusEnum;

/**
 * 封装异常抛出
 *
 * @author : zimin
 * @date : 2021/6/24 3:29 下午
 */
public interface GraceException {

    /**
     * <p>优雅抛出异常信息</p>
     *
     * @param msg 异常信息
     * @return void
     * @since 2022-06-16 11:41:58
     */
    static void display(String msg) {
        throw new InjectException(msg);
    }

    /**
     * <p>自定义异常返回信息</p>
     *
     * @param responseStatusEnum
     * @return void
     * @since 2022-04-05 10:24:34
     */
    static void display(ResponseStatusEnum responseStatusEnum) {
        throw new InjectException(responseStatusEnum);
    }

    /**
     * <p>为空断言</p>
     *
     * @param object 校验对象
     * @param responseStatusEnum 返回异常信息
     * @since 2022-06-16 11:42:27
     */
    static void isNull(Object object, ResponseStatusEnum responseStatusEnum) {
        if (ObjectUtils.isEmpty(object)) {
            display(responseStatusEnum);
        }
    }

    /**
     * <p>不为空断言</p>
     *
     * @param object 校验对象
     * @param responseStatusEnum 返回异常信息
     * @since 2022-06-16 11:42:27
     */
    static void isNotNull(Object object, ResponseStatusEnum responseStatusEnum) {
        if (ObjectUtils.isNotEmpty(object)) {
            display(responseStatusEnum);
        }
    }

    /**
     * <p>false 断言</p>
     *
     * @param expression 校验表达式
     * @param responseStatusEnum 返回异常信息
     * @since 2022-06-16 11:42:27
     */
    static void isFalse(boolean expression, ResponseStatusEnum responseStatusEnum) {
        if (!expression) {
            display(responseStatusEnum);
        }
    }

    /**
     * <p>true 断言</p>
     *
     * @param expression 校验表达式
     * @param responseStatusEnum 返回异常信息
     * @since 2022-06-16 11:42:27
     */
    static void isTrue(boolean expression, ResponseStatusEnum responseStatusEnum) {
        if (expression) {
            display(responseStatusEnum);
        }
    }

}
